package com.shuwei.location.db;

import android.content.Context;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by huanghaiqi on 2017/11/5.
 */

public class DaoFactory {
    public static <T extends Dao> T getDao(Class<T> clz, Context context, int version) {
        Dao dao = null;
        try {
            Constructor<T> constructor = clz.getConstructor(Context.class, int.class);
//            constructor.setAccessible(true);
            T t = constructor.newInstance(context, version);
            return t;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
